<?php

namespace App\Console\Commands;

use App\Models\User;
use App\Services\User\UserUuidService;
use Illuminate\Console\Command;

class UuidMigrateCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'uuid:migrate';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'uuid migrate';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $users = User::query()->select('id')->get();
        $this->info(sprintf("=== Total Users: %s", count($users)));
        foreach ($users as $user) {
            $user->update([
                'uuid' => UserUuidService::encode($user->id),
            ]);
        }
        $this->info("== Done");
    }
}
